<!DOCTYPE html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="David的博客 |  David&#39;s Blog">
    <meta name="keyword" content="程序员小冰 David&#39;s Blog">
    <link rel="shortcut icon" href="/blog/img/favicon.ico">

    <title>
        
        【Linux】Linux基本常用命令手册 - David 的博客 | David&#39;s Blog
        
    </title>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/aircloud.css">
    <link rel="stylesheet" href="/blog/css/gitment.css">
    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
</head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> David Blog </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar radius">
            <img src="/blog/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>David</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/blog/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/blog/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/blog/archives">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/blog/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#系统服务管理"><span class="toc-text">系统服务管理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#systemctl"><span class="toc-text">systemctl</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文件管理"><span class="toc-text">文件管理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#ls"><span class="toc-text">ls</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#pwd"><span class="toc-text">pwd</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cd"><span class="toc-text">cd</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#date"><span class="toc-text">date</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#passwd"><span class="toc-text">passwd</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#su"><span class="toc-text">su</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#clear"><span class="toc-text">clear</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#man"><span class="toc-text">man</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#who"><span class="toc-text">who</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#free"><span class="toc-text">free</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ps"><span class="toc-text">ps</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#top"><span class="toc-text">top</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mkdir"><span class="toc-text">mkdir</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#more"><span class="toc-text">more</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cat"><span class="toc-text">cat</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#rm"><span class="toc-text">rm</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#touch"><span class="toc-text">touch</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cp"><span class="toc-text">cp</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mv"><span class="toc-text">mv</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#压缩与解压"><span class="toc-text">压缩与解压</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#tar"><span class="toc-text">tar</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#磁盘和网络管理"><span class="toc-text">磁盘和网络管理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#df"><span class="toc-text">df</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ifconfig"><span class="toc-text">ifconfig</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#netstat"><span class="toc-text">netstat</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#wget"><span class="toc-text">wget</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#软件的安装与管理"><span class="toc-text">软件的安装与管理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#rpm"><span class="toc-text">rpm</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#yum"><span class="toc-text">yum</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#网络安全"><span class="toc-text">网络安全</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#iptables"><span class="toc-text">iptables</span></a></li></ol></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> David Blog </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        【Linux】Linux基本常用命令手册
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2015-08-08 11:11:11</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/blog/tags/#Linux" title="Linux">Linux</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content ">
        <h2 id="系统服务管理"><a href="#系统服务管理" class="headerlink" title="系统服务管理"></a>系统服务管理</h2><h3 id="systemctl"><a href="#systemctl" class="headerlink" title="systemctl"></a>systemctl</h3><ul>
<li>启动服务：systemctl start httpd.service</li>
<li>关闭服务：systemctl stop httpd.service</li>
<li>重启服务（不管是否在运行）：systemctl restart httpd.service</li>
<li>重新载入配置（不中断服务）：systemctl reload httpd.service</li>
<li>查看运行状态：systemctl status httpd.service</li>
<li>设置开机启动：systemctl enable httpd.service</li>
<li>禁止开机启动：systemctl disable httpd.service</li>
<li>查看系统安装的服务：systemctl list-units –type=service</li>
</ul>
<h2 id="文件管理"><a href="#文件管理" class="headerlink" title="文件管理"></a>文件管理</h2><h3 id="ls"><a href="#ls" class="headerlink" title="ls"></a>ls</h3><p>列出/home目录下的子目录：ls -l /home<br>列出当前文件夹下所有文件夹及文件大小：ls -lht </p>
<h3 id="pwd"><a href="#pwd" class="headerlink" title="pwd"></a>pwd</h3><p>显示当前工作目录</p>
<h3 id="cd"><a href="#cd" class="headerlink" title="cd"></a>cd</h3><p>切换目录： cd /usr/local</p>
<h3 id="date"><a href="#date" class="headerlink" title="date"></a>date</h3><p>以指定格式显示日期；date ‘+date:%x time:%X’</p>
<h3 id="passwd"><a href="#passwd" class="headerlink" title="passwd"></a>passwd</h3><p>修改root密码：passwd root</p>
<h3 id="su"><a href="#su" class="headerlink" title="su"></a>su</h3><p>普通用户切换到超级用户：su -</p>
<h3 id="clear"><a href="#clear" class="headerlink" title="clear"></a>clear</h3><p>清除屏幕信息</p>
<h3 id="man"><a href="#man" class="headerlink" title="man"></a>man</h3><p>查看ls命令的帮助信息：man ls</p>
<h3 id="who"><a href="#who" class="headerlink" title="who"></a>who</h3><ul>
<li>查看当前运行级别：who -r</li>
<li>显示用的登录详情：who -buT</li>
</ul>
<h3 id="free"><a href="#free" class="headerlink" title="free"></a>free</h3><p>以MB显示内存使用状态：free -m</p>
<h3 id="ps"><a href="#ps" class="headerlink" title="ps"></a>ps</h3><p>查看系统所有进程：ps -ef<br>查看运行的java进程： ps -ef | grep java</p>
<h3 id="top"><a href="#top" class="headerlink" title="top"></a>top</h3><p>查看系统当前活跃进程信息</p>
<h3 id="mkdir"><a href="#mkdir" class="headerlink" title="mkdir"></a>mkdir</h3><p>创建目录</p>
<h3 id="more"><a href="#more" class="headerlink" title="more"></a>more</h3><p>分页查看<br>每10行显示一屏查看：more -c -10 </p>
<h3 id="cat"><a href="#cat" class="headerlink" title="cat"></a>cat</h3><p>查看config文件：cat -Ab config</p>
<h3 id="rm"><a href="#rm" class="headerlink" title="rm"></a>rm</h3><ul>
<li>删除文件：rm a.txt</li>
<li>删除文件夹： rm -rf a/</li>
</ul>
<h3 id="touch"><a href="#touch" class="headerlink" title="touch"></a>touch</h3><p>创建一个文件：touch a.txt</p>
<h3 id="cp"><a href="#cp" class="headerlink" title="cp"></a>cp</h3><p>将目录a的文件拷贝到目录b: cp -r /home/a /home/b</p>
<h3 id="mv"><a href="#mv" class="headerlink" title="mv"></a>mv</h3><p>移动或覆盖文件：mv a.txt b.txt</p>
<h2 id="压缩与解压"><a href="#压缩与解压" class="headerlink" title="压缩与解压"></a>压缩与解压</h2><h3 id="tar"><a href="#tar" class="headerlink" title="tar"></a>tar</h3><ul>
<li>打包文件夹到单独的文件：tar -cvf /opt/etc.tar /etc</li>
<li>压缩文件夹到压缩文件（gzip）：tar -zcvf /opt/etc.tar.gz /etc</li>
<li>压缩文件夹到压缩文件（bzip2）：tar -jcvf /opt/etc.tar.bz2 /etc</li>
<li>查阅压缩包中内容（gzip）：tar -ztvf /opt/etc.tar.gz /etc</li>
<li>解压文件到当前目录（gzip）：tar -zxvf /opt/etc.tar.gz</li>
</ul>
<h2 id="磁盘和网络管理"><a href="#磁盘和网络管理" class="headerlink" title="磁盘和网络管理"></a>磁盘和网络管理</h2><h3 id="df"><a href="#df" class="headerlink" title="df"></a>df</h3><p>查看磁盘占用情况：df -hT</p>
<h3 id="ifconfig"><a href="#ifconfig" class="headerlink" title="ifconfig"></a>ifconfig</h3><p>查看当前网络接口状态</p>
<h3 id="netstat"><a href="#netstat" class="headerlink" title="netstat"></a>netstat</h3><ul>
<li>查看路由信息：netstat -rn</li>
<li>查看所有有效TCP连接：netstat -an</li>
<li>查看系统中启动的监听服务：netstat -tulnp</li>
<li>查看处于连接状态的系统资源信息：netstat -atunp</li>
</ul>
<h3 id="wget"><a href="#wget" class="headerlink" title="wget"></a>wget</h3><p>从网络上下载软件</p>
<h2 id="软件的安装与管理"><a href="#软件的安装与管理" class="headerlink" title="软件的安装与管理"></a>软件的安装与管理</h2><h3 id="rpm"><a href="#rpm" class="headerlink" title="rpm"></a>rpm</h3><ul>
<li>安装软件包：rpm -ivh nginx-1.12.2-2.el7.x86_64.rpm</li>
<li>模糊搜索软件包：rpm -qa | grep nginx</li>
<li>精确查找软件包：rpm -qa nginx</li>
<li>查询软件包的安装路径：rpm -ql nginx-1.12.2-2.el7.x86_64</li>
<li>查看软件包的概要信息：rpm -qi nginx-1.12.2-2.el7.x86_64</li>
<li>验证软件包内容和安装文件是否一致：rpm -V nginx-1.12.2-2.el7.x86_64</li>
<li>更新软件包：rpm -Uvh nginx-1.12.2-2.el7.x86_64</li>
<li>删除软件包：rpm -e nginx-1.12.2-2.el7.x86_64</li>
</ul>
<h3 id="yum"><a href="#yum" class="headerlink" title="yum"></a>yum</h3><ul>
<li>安装软件包： yum install nginx</li>
<li>检查可以更新的软件包：yum check-update</li>
<li>更新指定的软件包：yum update nginx</li>
<li>在资源库中查找软件包信息：yum info nginx*</li>
<li>列出已经安装的所有软件包：yum info installed</li>
<li>列出软件包名称：yum list redis*</li>
<li>模糊搜索软件包：yum search redis</li>
</ul>
<h2 id="网络安全"><a href="#网络安全" class="headerlink" title="网络安全"></a>网络安全</h2><h3 id="iptables"><a href="#iptables" class="headerlink" title="iptables"></a>iptables</h3><ul>
<li>开启防火墙：systemctl start iptables.service</li>
<li>关闭防火墙：systemctl stop iptables.service</li>
<li>查看防火墙状态：systemctl status iptables.service</li>
<li>设置开机启动：systemctl enable iptables.service</li>
<li>禁用开机启动：systemctl disable iptables.service</li>
<li>查看filter表的链信息：iptables -L -n</li>
<li>查看NAT表的链信息：iptables -t nat -L -n</li>
<li>清除防火墙所有规则：iptables -F;iptables -X;iptables -Z;</li>
<li>添加过滤规则（开发80端口）：iptables -I INPUT -p tcp –dport 80 -j ACCEPT</li>
<li>查找规则所做行号：iptables -L INPUT –line-numbers -n</li>
<li>根据行号删除过滤规则：iptables -D INPUT 1</li>
</ul>

        
            <div class="donate-container">
    <div class="donate-button">
        <button id="donate-button">赞赏</button>
    </div>
    <div class="donate-img-container hide" id="donate-img-container">
        <img id="donate-img" src="" data-src="/blog/img/donate.jpg">
        <p> 感谢鼓励 </p>
    </div>
</div>
        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        <li>
            <a target="_blank" href="https://twitter.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-twitter"></i>
                            </span>
            </a>
        </li>
        
        
        <li>
            <a target="_blank" href="https://www.zhihu.com/people/mcxiaobing">
                            <span class="fa-stack fa-lg">
                                 <i class="iconfont icon-zhihu"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank" href="http://weibo.com/mcxiaobing">
                            <span class="fa-stack fa-lg">
                                  <i class="iconfont icon-weibo"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank" href="https://www.facebook.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-facebook"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank"  href="https://github.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-github"></i>
                            </span>
            </a>
        </li>
        

        

    </ul>
    
    <p>
        <span>/</span>
        
        <span><a href="https://segmentfault.com/u/mcxiaobing">思否</a></span>
        <span>/</span>
        
        <span><a href="https://juejin.im/user/57edcdb2a0bb9f0058ed8ed9">掘金</a></span>
        <span>/</span>
        
        <span><a href="https://www.jianshu.com/u/4e2015c5a972">简书</a></span>
        <span>/</span>
        
        <span><a href="https://gitee.com/mcxiaobing">码云</a></span>
        <span>/</span>
        
    </p>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a href="https://hexo.io/">Hexo</a>  Theme <a href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/blog/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="/blog/js/index.js"></script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




</html>
